
/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

/**
 * Flash Player version data.
 * 
 * <p>Take a look at {@link fever.core.client.ClientContext} to see example.
 * 
 * @see fever.core.client.ClientContext#player
 * 
 * @author Romain Ecarnot
 */
class fever.core.client.ClientPlayer
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _major : Number;
	private var _minor : Number;	private var _revision : Number;
	private var _type : String;
	
	
	//-------------------------------------------------------------------------
	// Public Properties
	//-------------------------------------------------------------------------
	
	/** Major of Flash player. */
	public function get major() : Number { return _major; }
	
	/** Minor of Flash player. */
	public function get minor() : Number { return _minor; }
	
	/** Revision of Flash player. */
	public function get revision() : Number { return _revision; }
	
	/** Type of Flash player. */	public function get type() : String { return _type; }
	 
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function ClientPlayer()
	{
		var v : Array = System.capabilities.version.split(" ");
		var a : Array = v[1].split(",");
		_major = Number( a[0] );
		_minor = Number( a[1] );
		_revision = Number( a[2] );
		
		_type = System.capabilities.playerType;
	}
	
	/**
	 * Checks if passed in flash player version is compliant to current 
	 * supported version.
	 * 
	 * @param maj Major version
	 * @param min Minor version
	 * @param rev ( optional ) revision version
	 * 
	 * @return {@code true} if version is compliant ( >= )
	 */
	public function isCompliant( maj : Number, min : Number, rev : Number ) : Boolean
	{
		if( maj == undefined || min == undefined ) return false;
		if( rev == undefined ) rev = 0;
		
		if( _major < maj ) return false;
		if( _major > maj ) return true;
		if( _minor < min ) return false;
		if( _minor > min ) return true;
		if( _revision < rev) return false;
		return true;
	}
	
	/**
	 * Returns {@code true} if current player has "FullScreen mode" support.
	 * 
	 * <p>Player is compliant if version >= 9.0.18
	 */
	public function isFullScreenCompliant() : Boolean
	{
		return isCompliant( 9,0,18 );
	}
	
	/**
	 * Returns player version "only" in string format. 
	 */
	public function getVersion() : String
	{
		return _major + "." + _minor + "." + _revision;
	}
	
	/**
	 * Returns player string version
	 */
	public function toString() : String
	{
		return "Flash Player " +_major + "." + _minor + "." + _revision;
	}		
}